#!/usr/bin/env python
# -*- coding:UTF-8 -*-
"""
dongxiaoyong
2018/4/23
model.py
"""
import json


class Product(object):
    def __init__(self, pid, pname, sid, sname, cid, cname, unum, uprice, snum, onum, ronum, isabord):
        self.productid = pid
        self.productname = pname
        self.supplierid = sid
        self.suppliername = sname
        self.categoryid = cid
        self.categoryname = cname
        self.unitnum = unum
        self.unitprice = uprice
        self.stocknum = snum
        self.ordernum = onum
        self.reordernum = ronum
        self.isabord = isabord


class ProductEncoder(json.JSONEncoder):
    """用于定义反序列化方式，在 json.dumps(items, clas=ProductEncoder)方法中使用"""

    def default(self, obj):
        if isinstance(obj, Product):
            return obj.__dict__
        return json.JSONEncoder.default(self, obj)


class Supplier(object):
    def __init__(self, sid, sname):
        self.supplierid = sid
        self.suppliername = sname


class Category(object):
    def __init__(self, cid, cname):
        self.categoryid = cid
        self.categoryname = cname
